﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TestAngular.Migrations
{
    public partial class BasicArchives : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "BasicArchivesCustomerType",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Level = table.Column<int>(type: "int", nullable: false),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DisplayName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    CustomerTypeId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesCustomerType", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesCustomerType_BasicArchivesCustomerType_CustomerTypeId",
                        column: x => x.CustomerTypeId,
                        principalTable: "BasicArchivesCustomerType",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_BasicArchivesCustomerType_BasicArchivesCustomerType_ParentId",
                        column: x => x.ParentId,
                        principalTable: "BasicArchivesCustomerType",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesDepartment",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Level = table.Column<int>(type: "int", nullable: false),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DisplayName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    DepartmentId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesDepartment", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesDepartment_BasicArchivesDepartment_DepartmentId",
                        column: x => x.DepartmentId,
                        principalTable: "BasicArchivesDepartment",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_BasicArchivesDepartment_BasicArchivesDepartment_ParentId",
                        column: x => x.ParentId,
                        principalTable: "BasicArchivesDepartment",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesItemCategory",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Level = table.Column<int>(type: "int", nullable: false),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DisplayName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    ItemCategoryId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesItemCategory", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesItemCategory_BasicArchivesItemCategory_ItemCategoryId",
                        column: x => x.ItemCategoryId,
                        principalTable: "BasicArchivesItemCategory",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_BasicArchivesItemCategory_BasicArchivesItemCategory_ParentId",
                        column: x => x.ParentId,
                        principalTable: "BasicArchivesItemCategory",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesSaleOrderType",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DisplayName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesSaleOrderType", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesSerialNumbers",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Key = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Value = table.Column<long>(type: "bigint", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesSerialNumbers", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesSupplierType",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Level = table.Column<int>(type: "int", nullable: false),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DisplayName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    SupplierTypeId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesSupplierType", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesSupplierType_BasicArchivesSupplierType_ParentId",
                        column: x => x.ParentId,
                        principalTable: "BasicArchivesSupplierType",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BasicArchivesSupplierType_BasicArchivesSupplierType_SupplierTypeId",
                        column: x => x.SupplierTypeId,
                        principalTable: "BasicArchivesSupplierType",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesUnit",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DisplayName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesUnit", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesWorkCenter",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Name = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    StandardCapacity = table.Column<int>(type: "int", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesWorkCenter", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesOperator",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DepartmentId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    OperatorType = table.Column<int>(type: "int", nullable: false),
                    Enabled = table.Column<bool>(type: "bit", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesOperator", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesOperator_BasicArchivesDepartment_DepartmentId",
                        column: x => x.DepartmentId,
                        principalTable: "BasicArchivesDepartment",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesItemMaster",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    ItemCategoryId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    Spec = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    UnitGroupId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    UnitGroup = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CanBePurchased = table.Column<bool>(type: "bit", nullable: false),
                    Sellable = table.Column<bool>(type: "bit", nullable: false),
                    CanBeProduced = table.Column<bool>(type: "bit", nullable: false),
                    CanBeOutsourced = table.Column<bool>(type: "bit", nullable: false),
                    Enabled = table.Column<bool>(type: "bit", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesItemMaster", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesItemMaster_BasicArchivesItemCategory_ItemCategoryId",
                        column: x => x.ItemCategoryId,
                        principalTable: "BasicArchivesItemCategory",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesUnitGroup",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    GroupName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    MainUnitId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesUnitGroup", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesUnitGroup_BasicArchivesUnit_MainUnitId",
                        column: x => x.MainUnitId,
                        principalTable: "BasicArchivesUnit",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesEquipment",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    WorkCenterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Name = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    Quantity = table.Column<int>(type: "int", nullable: false, defaultValue: 1),
                    StandardCapacity = table.Column<int>(type: "int", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesEquipment", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesEquipment_BasicArchivesWorkCenter_WorkCenterId",
                        column: x => x.WorkCenterId,
                        principalTable: "BasicArchivesWorkCenter",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesCustomer",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    CustomerTypeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    ShortName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    Contact = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Phone = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
                    Address = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    OperatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Enabled = table.Column<bool>(type: "bit", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesCustomer", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesCustomer_BasicArchivesCustomerType_CustomerTypeId",
                        column: x => x.CustomerTypeId,
                        principalTable: "BasicArchivesCustomerType",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_BasicArchivesCustomer_BasicArchivesOperator_OperatorId",
                        column: x => x.OperatorId,
                        principalTable: "BasicArchivesOperator",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesSupplier",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    SupplierTypeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    ShortName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    Contact = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Phone = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
                    Address = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    OperatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Enabled = table.Column<bool>(type: "bit", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesSupplier", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesSupplier_BasicArchivesOperator_OperatorId",
                        column: x => x.OperatorId,
                        principalTable: "BasicArchivesOperator",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BasicArchivesSupplier_BasicArchivesSupplierType_SupplierTypeId",
                        column: x => x.SupplierTypeId,
                        principalTable: "BasicArchivesSupplierType",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesWarehouse",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Name = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    OperatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    AllowNegativeInventory = table.Column<bool>(type: "bit", nullable: false),
                    Enabled = table.Column<bool>(type: "bit", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesWarehouse", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesWarehouse_BasicArchivesOperator_OperatorId",
                        column: x => x.OperatorId,
                        principalTable: "BasicArchivesOperator",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesAuxiliaryUnit",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    UnitId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MainToAuxiliaryRatio = table.Column<int>(type: "int", nullable: false),
                    AuxiliaryToMainRatio = table.Column<int>(type: "int", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    MainArchiveId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesAuxiliaryUnit", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesAuxiliaryUnit_BasicArchivesUnit_UnitId",
                        column: x => x.UnitId,
                        principalTable: "BasicArchivesUnit",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BasicArchivesAuxiliaryUnit_BasicArchivesUnitGroup_MainArchiveId",
                        column: x => x.MainArchiveId,
                        principalTable: "BasicArchivesUnitGroup",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesSaleOrder",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    OrderTypeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CustomerId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    OperatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Mark = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    BussinessDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    DocumentStatus = table.Column<int>(type: "int", nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesSaleOrder", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesSaleOrder_BasicArchivesCustomer_CustomerId",
                        column: x => x.CustomerId,
                        principalTable: "BasicArchivesCustomer",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BasicArchivesSaleOrder_BasicArchivesOperator_OperatorId",
                        column: x => x.OperatorId,
                        principalTable: "BasicArchivesOperator",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BasicArchivesSaleOrder_BasicArchivesSaleOrderType_OrderTypeId",
                        column: x => x.OrderTypeId,
                        principalTable: "BasicArchivesSaleOrderType",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "BasicArchivesSaleOrderLine",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ItemMasterId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ItemCode = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    ItemName = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
                    ItemSpec = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    Quantity = table.Column<decimal>(type: "decimal(18,6)", nullable: false),
                    UnitId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    UnitPrice = table.Column<decimal>(type: "decimal(18,6)", nullable: false),
                    DeliveryDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DocumentId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    LineNo = table.Column<int>(type: "int", nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesSaleOrderLine", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesSaleOrderLine_BasicArchivesAuxiliaryUnit_UnitId",
                        column: x => x.UnitId,
                        principalTable: "BasicArchivesAuxiliaryUnit",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BasicArchivesSaleOrderLine_BasicArchivesItemMaster_ItemMasterId",
                        column: x => x.ItemMasterId,
                        principalTable: "BasicArchivesItemMaster",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BasicArchivesSaleOrderLine_BasicArchivesSaleOrder_DocumentId",
                        column: x => x.DocumentId,
                        principalTable: "BasicArchivesSaleOrder",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesAuxiliaryUnit_MainArchiveId",
                table: "BasicArchivesAuxiliaryUnit",
                column: "MainArchiveId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesAuxiliaryUnit_UnitId",
                table: "BasicArchivesAuxiliaryUnit",
                column: "UnitId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesCustomer_CustomerTypeId",
                table: "BasicArchivesCustomer",
                column: "CustomerTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesCustomer_OperatorId",
                table: "BasicArchivesCustomer",
                column: "OperatorId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesCustomerType_CustomerTypeId",
                table: "BasicArchivesCustomerType",
                column: "CustomerTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesCustomerType_ParentId",
                table: "BasicArchivesCustomerType",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesDepartment_DepartmentId",
                table: "BasicArchivesDepartment",
                column: "DepartmentId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesDepartment_ParentId",
                table: "BasicArchivesDepartment",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesEquipment_WorkCenterId",
                table: "BasicArchivesEquipment",
                column: "WorkCenterId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesItemCategory_ItemCategoryId",
                table: "BasicArchivesItemCategory",
                column: "ItemCategoryId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesItemCategory_ParentId",
                table: "BasicArchivesItemCategory",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesItemMaster_ItemCategoryId",
                table: "BasicArchivesItemMaster",
                column: "ItemCategoryId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesOperator_DepartmentId",
                table: "BasicArchivesOperator",
                column: "DepartmentId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesSaleOrder_CustomerId",
                table: "BasicArchivesSaleOrder",
                column: "CustomerId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesSaleOrder_OperatorId",
                table: "BasicArchivesSaleOrder",
                column: "OperatorId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesSaleOrder_OrderTypeId",
                table: "BasicArchivesSaleOrder",
                column: "OrderTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesSaleOrderLine_DocumentId",
                table: "BasicArchivesSaleOrderLine",
                column: "DocumentId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesSaleOrderLine_ItemMasterId",
                table: "BasicArchivesSaleOrderLine",
                column: "ItemMasterId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesSaleOrderLine_UnitId",
                table: "BasicArchivesSaleOrderLine",
                column: "UnitId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesSupplier_OperatorId",
                table: "BasicArchivesSupplier",
                column: "OperatorId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesSupplier_SupplierTypeId",
                table: "BasicArchivesSupplier",
                column: "SupplierTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesSupplierType_ParentId",
                table: "BasicArchivesSupplierType",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesSupplierType_SupplierTypeId",
                table: "BasicArchivesSupplierType",
                column: "SupplierTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesUnitGroup_MainUnitId",
                table: "BasicArchivesUnitGroup",
                column: "MainUnitId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesWarehouse_OperatorId",
                table: "BasicArchivesWarehouse",
                column: "OperatorId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "BasicArchivesEquipment");

            migrationBuilder.DropTable(
                name: "BasicArchivesSaleOrderLine");

            migrationBuilder.DropTable(
                name: "BasicArchivesSerialNumbers");

            migrationBuilder.DropTable(
                name: "BasicArchivesSupplier");

            migrationBuilder.DropTable(
                name: "BasicArchivesWarehouse");

            migrationBuilder.DropTable(
                name: "BasicArchivesWorkCenter");

            migrationBuilder.DropTable(
                name: "BasicArchivesAuxiliaryUnit");

            migrationBuilder.DropTable(
                name: "BasicArchivesItemMaster");

            migrationBuilder.DropTable(
                name: "BasicArchivesSaleOrder");

            migrationBuilder.DropTable(
                name: "BasicArchivesSupplierType");

            migrationBuilder.DropTable(
                name: "BasicArchivesUnitGroup");

            migrationBuilder.DropTable(
                name: "BasicArchivesItemCategory");

            migrationBuilder.DropTable(
                name: "BasicArchivesCustomer");

            migrationBuilder.DropTable(
                name: "BasicArchivesSaleOrderType");

            migrationBuilder.DropTable(
                name: "BasicArchivesUnit");

            migrationBuilder.DropTable(
                name: "BasicArchivesCustomerType");

            migrationBuilder.DropTable(
                name: "BasicArchivesOperator");

            migrationBuilder.DropTable(
                name: "BasicArchivesDepartment");
        }
    }
}
